home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / videbjct / vidbjcts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  12.4 KB  |  564 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/VideoObject/RCS/videoObjects.c,v 1.17 93/02/07 13:04:04 drapeau Exp $ */
  25. /* $Log:    videoObjects.c,v $
  26.  * Revision 1.17  93/02/07  13:04:04  drapeau
  27.  * Fixed minor error in communications specifications for Sony 1550 driver.
  28.  * 
  29.  * Revision 1.16  92/11/17  14:46:44  drapeau
  30.  * Corrected errors in configuration of several players, especially the
  31.  * Pioneer4200 player.
  32.  * 
  33.  * Revision 1.15  92/10/01  17:11:45  drapeau
  34.  * Updated Config structures for several of the devices supported by the
  35.  * library, in keeping with improvements in the serial line communications
  36.  * code.
  37.  * 
  38.  * Revision 1.14  92/09/03  10:25:12  drapeau
  39.  * Changed communications settings for the NEC driver configuration.
  40.  * 
  41.  * Revision 1.13  92/09/02  17:14:04  drapeau
  42.  * Modified device-specific Config structs to reflect the addition of a
  43.  * new field, "flowControl".
  44.  * 
  45.  * Revision 1.12  92/09/01  16:58:56  drapeau
  46.  * A couple of changes:
  47.  * * Updated copyright notice.
  48.  * * Updated default Config structures to reflect new methods added to the
  49.  *   VideoObject.
  50.  * * Cosmetic changes to make code easier to read.
  51.  * * Added function prototypes for better ANSI compliance.
  52.  * 
  53.  * Revision 1.11  92/07/30  15:15:57  drapeau
  54.  * Improved method for setting asynchronous read function.  The previous
  55.  * version, although designed to be independent of any window system or
  56.  * programming toolkit, was still too reliant on the XView toolkit.  This
  57.  * error no longer exists.
  58.  * Also, minor change to PrintDiagnostics() function; it no longer
  59.  * explicitly terminates with a "\n"; the caller must decide that a
  60.  * "\n" is wanted at the end of the string.
  61.  * 
  62.  * Revision 1.10  92/06/16  23:49:15  drapeau
  63.  * Made a number of changes:
  64.  * * Added support for the Sony CVD1000 (aka "Vdeck") device.
  65.  * * Added 'SetAsynchReadFunction' so as to allow the use of generic toolkit
  66.  *   notify functions for file reads.  This is the first step toward making
  67.  *   the VideoObject toolkit-neutral.
  68.  * 
  69.  * Revision 1.0  91/11/15  17:38:28  collab
  70.  * Initial revision
  71.  * 
  72.  * Revision 0.18  91/09/29  16:12:47  lim
  73.  * Put in all drivers.
  74.  * Added DisplayChoice.
  75.  * 
  76.  * Revision 0.17  91/09/24  22:01:29  lim
  77.  * 1. Used relative filename for driver header file.
  78.  * 
  79.  * Revision 0.16  91/08/24  18:00:57  lim
  80.  * Implemented PrintDiagnostics.
  81.  * 
  82.  * Revision 0.15  91/08/23  17:24:48  lim
  83.  * Included NECDriver.h
  84.  * Clear Marker has been removed as one of the video
  85.  * object functions.
  86.  * 
  87.  * Revision 0.14  91/08/21  10:52:54  lim
  88.  * Added second parameter to DevInit(serialPort).
  89.  * 
  90.  * Revision 0.13  91/08/17  20:45:50  lim
  91.  * 1. Configuration no longer has field for 'interruptibleSegmentPlay'.
  92.  * 2. NECInterrupt becomes NECClearMarker.
  93.  * 
  94.  * Revision 0.12  91/08/15  13:04:51  lim
  95.  * *** empty log message ***
  96.  * 
  97.  * Revision 0.11  91/08/09  11:05:29  lim
  98.  * Moved 'NECDriver.h' from 'vcrEdit.h'
  99.  * 
  100.  * Revision 0.10  91/08/08  17:32:34  lim
  101.  * Initial revision.
  102.  * 
  103.  * Revision 0.11  91/08/07  13:33:39  lim
  104.  * 1. DevInit() now returns pointer to VideoObject.
  105.  * 2. Added instance pointer, "theObject" to all public function calls.
  106.  * 3. DisplayError() is added so that device drivers can call it to 
  107.  * display error messages.
  108.  * 
  109.  * Revision 0.10  91/08/02  12:45:00  lim
  110.  * Initial revision.
  111.  *  */
  112.  
  113. /* WRITING NEW APPLICATION...
  114.  * 1. Replace the header file below with the header file for your own application.
  115.  */
  116.  
  117. #include "vcrEdit.h"
  118. #include <Pioneer4200Driver.h>
  119. #include <PanasonicOptDriver.h>
  120. #include <Pioneer6000Driver.h>
  121. #include <Sony1550Driver.h>
  122. #include <NECDriver.h>
  123. #include <CVD1000Driver.h>
  124.  
  125. /* ADDING NEW DRIVERS...
  126.  * 1. Add name of player to the array below.
  127.  * 2. Increment 'numDevices'.
  128.  */
  129.  
  130. char allDevices[MaxDevices][MaxNameLength]= 
  131. {
  132.   "Pioneer4200",
  133.   "Pioneer6000",
  134.   "Panasonic2026",
  135.   "Sony1550",
  136.   "NEC",
  137.   "CVD1000"
  138.   }
  139. ;
  140. int numDevices = 6;
  141.  
  142.  
  143. /* INCLUDE VIDEO OBJECTS HERE */
  144.  
  145.  
  146. /* Video Object for Pioneer4200 */
  147.  
  148. static Config Pioneer4200Config = 
  149. {
  150.   "Pioneer4200",
  151.   "/dev/ttya",
  152.   4800,
  153.   13,
  154.   8,
  155.   NoParity,
  156.   No,
  157.   No,
  158.   120,
  159.   -1
  160.   }
  161. ;
  162.  
  163. static VideoObject Pioneer4200Obj = 
  164. {
  165.   &Pioneer4200Config,
  166.   Pioneer4200Play,
  167.   Pioneer4200PlayFromTo,
  168.   Pioneer4200FastForward,
  169.   Pioneer4200Reverse,
  170.   Pioneer4200CalcSpeed,
  171.   Pioneer4200PlayAtSpeedDir,
  172.   Pioneer4200Step,
  173.   Pioneer4200Still,
  174.   Pioneer4200Stop,
  175.   Pioneer4200SetDefaults,
  176.   Pioneer4200SetAudio,
  177.   Pioneer4200SetVideo,
  178.   Pioneer4200SetAddMode,
  179.   Pioneer4200SetAddressDisplay,
  180.   Pioneer4200Eject,
  181.   Pioneer4200Power,
  182.   Pioneer4200QueryFrame,
  183.   Pioneer4200QueryChapter,
  184.   Pioneer4200QueryAudio,
  185.   Pioneer4200QueryVideo,
  186.   Pioneer4200QueryMedium,
  187.   Pioneer4200QueryStatus, 
  188.   Pioneer4200Ping,
  189.   NULL,
  190.   NULL
  191.   }
  192. ;
  193.  
  194. /* Video Object for CVD1000 */
  195.  
  196. static Config CVD1000Config = 
  197. {
  198.   "CVD1000",
  199.   "/dev/ttya",
  200.   9600,
  201.   -1,
  202.   8,
  203.   NoParity,
  204.   No,
  205.   No,
  206.   60,
  207.   -1
  208.   }
  209. ;
  210.  
  211. static VideoObject CVD1000Obj = 
  212. {
  213.   &CVD1000Config,
  214.   CVD1000Play,
  215.   CVD1000PlayFromTo,
  216.   CVD1000FastForward,
  217.   CVD1000Reverse,
  218.   CVD1000CalcSpeed,
  219.   CVD1000PlayAtSpeedDir,
  220.   CVD1000Step,
  221.   CVD1000Still,
  222.   CVD1000Stop,
  223.   CVD1000SetDefaults,
  224.   CVD1000SetAudio,
  225.   CVD1000SetVideo,
  226.   CVD1000SetAddMode,
  227.   CVD1000SetAddressDisplay,
  228.   CVD1000Eject,
  229.   CVD1000Power,
  230.   CVD1000QueryFrame,
  231.   CVD1000QueryChapter,
  232.   CVD1000QueryAudio,
  233.   CVD1000QueryVideo,
  234.   CVD1000QueryMedium,
  235.   CVD1000QueryStatus, 
  236.   CVD1000Ping,
  237.   CVD1000Record,
  238.   CVD1000RecordFromTo
  239.   }
  240. ;
  241.  
  242. /* Video Object for PanasonicOpticalDiskPlayer */
  243.  
  244. static Config PanasonicOptConfig = 
  245. {
  246.   "Panasonic2026",
  247.   "/dev/ttyb",
  248.   9600,
  249.   13,
  250.   8,
  251.   NoParity,
  252.   No,
  253.   No,
  254.   300, 
  255.   -1
  256.   }
  257. ;
  258.  
  259. static VideoObject PanasonicOptObj = 
  260. {
  261.   &PanasonicOptConfig,
  262.   PanasonicOptPlay,
  263.   PanasonicOptPlayFromTo,
  264.   PanasonicOptFastForward,
  265.   PanasonicOptReverse,
  266.   PanasonicOptCalcSpeed,
  267.   PanasonicOptPlayAtSpeedDir,
  268.   PanasonicOptStep,
  269.   PanasonicOptStill,
  270.   PanasonicOptStop,                            
  271.   PanasonicOptSetDefaults,                        
  272.   PanasonicOptSetAudio,                        
  273.   PanasonicOptSetVideo,
  274.   NULL,
  275.   PanasonicOptSetAddressDisplay,
  276.   PanasonicOptEject,
  277.   NULL,
  278.   PanasonicOptQueryFrame,
  279.   NULL,
  280.   NULL,
  281.   NULL,
  282.   PanasonicOptQueryMedium,
  283.   PanasonicOptQueryStatus,
  284.   PanasonicOptPing,
  285.   NULL,
  286.   NULL
  287.   }
  288. ;
  289.  
  290. /* Video Object for Pioneer6000 */
  291.  
  292. static Config Pioneer6000Config = 
  293. {
  294.   "Pioneer6000",
  295.   "/dev/ttyb",
  296.   9600,
  297.   13,
  298.   8,
  299.   NoParity,
  300.   No,
  301.   No,
  302.   90,
  303.   -1
  304.   }
  305. ;
  306.  
  307. static VideoObject Pioneer6000Obj = 
  308. {
  309.   &Pioneer6000Config,
  310.   Pioneer6000Play,
  311.   Pioneer6000PlayFromTo,
  312.   Pioneer6000FastForward,
  313.   Pioneer6000Reverse,
  314.   Pioneer6000CalcSpeed,
  315.   Pioneer6000PlayAtSpeedDir,
  316.   Pioneer6000Step,
  317.   Pioneer6000Still,
  318.   Pioneer6000Stop,                            
  319.   Pioneer6000SetDefaults,                        
  320.   Pioneer6000SetAudio,                        
  321.   Pioneer6000SetVideo,
  322.   NULL,
  323.   Pioneer6000SetAddressDisplay,
  324.   Pioneer6000Eject,
  325.   NULL,
  326.   Pioneer6000QueryFrame,
  327.   NULL,
  328.   NULL,
  329.   NULL,
  330.   NULL,
  331.   Pioneer6000QueryStatus,
  332.   Pioneer6000Ping,
  333.   NULL,
  334.   NULL
  335.   }
  336. ;
  337.  
  338. /* Video Object for Sony1550 */
  339.  
  340. static Config Sony1550Config = 
  341. {
  342.   "Sony1550",
  343.   "/dev/ttyb",
  344.   1200,
  345.   -1,
  346.   8,
  347.   NoParity,
  348.   Yes,
  349.   No,
  350.   90,
  351.   -1
  352.   }
  353. ;
  354.  
  355. static VideoObject Sony1550Obj = 
  356. {
  357.   &Sony1550Config,
  358.   Sony1550Play,
  359.   Sony1550PlayFromTo,
  360.   Sony1550FastForward,
  361.   Sony1550Reverse,
  362.   Sony1550CalcSpeed,
  363.   Sony1550PlayAtSpeedDir,
  364.   Sony1550Step,
  365.   Sony1550Still,
  366.   Sony1550Stop,                            
  367.   Sony1550SetDefaults,                        
  368.   Sony1550SetAudio,                        
  369.   Sony1550SetVideo,
  370.   Sony1550SetAddMode,
  371.   Sony1550SetAddressDisplay,
  372.   Sony1550Eject,
  373.   NULL,
  374.   Sony1550QueryFrame,
  375.   Sony1550QueryChapter,
  376.   NULL,
  377.   NULL,
  378.   Sony1550QueryMedium,
  379.   Sony1550QueryStatus,
  380.   Sony1550Ping,
  381.   NULL,
  382.   NULL
  383.   }
  384. ;
  385.  
  386.  
  387. /* Video Object for NEC PC VCR */
  388.  
  389. static Config NECConfig = 
  390. {
  391.   "NEC",
  392.   "/dev/ttya",
  393.   1200,
  394.   13,
  395.   8,
  396.   NoParity,
  397.   No,
  398.   No,
  399.   270,
  400.   -1
  401.   }
  402. ;
  403.  
  404. static VideoObject NECObj = 
  405. {
  406.   &NECConfig,
  407.   NECPlay,
  408.   NECPlayFromTo,
  409.   NECFastForward,
  410.   NECReverse,
  411.   NECCalcSpeed,
  412.   NECPlayAtSpeedDir,
  413.   NECStep,
  414.   NECStill,
  415.   NECStop,
  416.   NECSetDefaults,
  417.   NECSetAudio,
  418.   NECSetVideo,
  419.   NECSetAddressingMode,
  420.   NULL,
  421.   NECEject,
  422.   NECPower,
  423.   NECQueryFrame,
  424.   NULL,
  425.   NECQueryAudio,
  426.   NECQueryVideo,
  427.   NECReadHeader,
  428.   NECQueryStatus,
  429.   NECPing,
  430.   NECRecord,
  431.   NECRecordFromTo
  432.   }
  433. ;
  434.  
  435.  
  436. /* DevInit builds the video object for the appropriate ...
  437.  * ... device and sets up the serial line.  It returns the ...
  438.  * ... pointer to the video object.
  439.  */
  440.  
  441. VideoObject*
  442.   DevInit(char*    deviceName,
  443.       char* serialPort)
  444. {
  445.   VideoObject* myVideo;
  446.   
  447.   /* ADDING NEW DRIVERS
  448.      ... Add statements for new device here, as another else-if statement */
  449.   
  450.   if (strcmp(deviceName, "Pioneer4200") == 0)                /* Set the video object to the appropriate variable */
  451.     myVideo = BuildVideoObject(&Pioneer4200Obj);
  452.   else if (strcmp(deviceName, "Sony1550") == 0)
  453.     myVideo = BuildVideoObject(&Sony1550Obj);
  454.   else if (strcmp(deviceName, "Panasonic2026") == 0)
  455.     myVideo = BuildVideoObject(&PanasonicOptObj);
  456.   else if (strcmp(deviceName, "Pioneer6000") == 0)
  457.     myVideo = BuildVideoObject(&Pioneer6000Obj);
  458.   else if (strcmp(deviceName, "NEC") == 0)
  459.     myVideo = BuildVideoObject(&NECObj);                
  460.   else if (strcmp(deviceName, "CVD1000") == 0)
  461.     myVideo = BuildVideoObject(&CVD1000Obj);                
  462.   
  463.   if (PlayerVerified(myVideo, serialPort) != -1)            /* Sets up serial line for communicating with the device */
  464.     if (SetSerialLine(myVideo->DevConfig, serialPort))
  465.       return myVideo;
  466.     else
  467.       return NULL;
  468.   else
  469.     return NULL;
  470. }                                    /* end function DevInit */
  471.  
  472.  
  473.  
  474. /* WRITING NEW APPLICATIONS... 
  475.  * Optional : Replace the code within DisplayError() if a different 
  476.  * error notification function is desired.
  477.  *
  478.  * DO NOT remove the function DisplayError().
  479.  * 
  480.  * DisplayError() is useful in displaying errors other than those dealing
  481.  * with the device.
  482.  */
  483.  
  484. /* WRITING NEW DRIVERS...
  485.  * IMPORTANT : 
  486.  * Video drivers should be written such that any detectable error
  487.  * is decoded into English and placed into at most 2 strings. Then the
  488.  * driver is responsible for calling DisplayError() which displays the
  489.  * errors appropriately to the user.
  490.  */
  491.  
  492. /* DisplayError takes 2 strings that explain the error condition encountered.
  493.  */
  494. void
  495. DisplayError(char* errorMsg1,
  496.          char* errorMsg2)
  497. {
  498.   notice_prompt(vcrEdit_window1->window1, NULL,
  499.         NOTICE_MESSAGE_STRINGS,
  500.         errorMsg1,
  501.         errorMsg2,
  502.         NULL,
  503.         NOTICE_BUTTON,    "OK", 100,
  504.         NULL);
  505. }
  506.  
  507.  
  508. /* Display choice message */
  509. int
  510. DisplayChoice(char* msg1,
  511.           char* msg2,
  512.           char* r1,
  513.           char* r2)
  514. {
  515.   int result = notice_prompt(vcrEdit_window1->window1, NULL,
  516.                  NOTICE_MESSAGE_STRINGS,
  517.                  msg1, msg2,
  518.                  NULL,
  519.                  NOTICE_BUTTON_YES, r1,
  520.                  NOTICE_BUTTON_NO, r2, 
  521.                  NULL);
  522.   return result;
  523.   
  524. }
  525.  
  526.  
  527. void
  528. PrintDiagnostics(char* msg)
  529. {
  530.   if (diagMode == Yes)
  531.     fprintf(stderr, "%s", msg);
  532. }
  533.  
  534.  
  535. static int (*callbackProc)(int);                    /* Pointer to function called when asynch read is needed */
  536.  
  537.     
  538. Notify_value MyAsyncCallback(Notify_client    client,
  539.                  int        fd)
  540. {
  541.   return((*callbackProc) (fd));
  542. }                                    /* end function MyAsyncCallback */
  543.  
  544.  
  545.  
  546. void 
  547. SetAsynchReadFunction(int    (*callback)(int),
  548.               int    fd,
  549.               int    onOrOff)
  550. {
  551.   /* Code here would use the callback function provided to be
  552.      called when input occurred on the file descriptor of "theObject".
  553.      For XView, the code might be this:
  554.      */
  555.   callbackProc = callback;
  556.   
  557.   if (onOrOff == FeatureOn)
  558.     notify_set_input_func((Notify_client) AppClient, 
  559.               MyAsyncCallback, fd);
  560.   else
  561.     notify_set_input_func((Notify_client) AppClient,
  562.               NOTIFY_FUNC_NULL, fd);            /* Turn off automatic read */
  563. }                                    /* end function SetAsynchReadFunction */
  564.